from langchain.text_splitter import CharacterTextSplitter
# 构建Ollama部署的本地模型
def get_llm_ollama():
    from langchain_community.llms import Ollama
    llm = Ollama(model="qwen2:7b")
    return llm

# URL 网页加载器生成文档
def load_docs_url():
    from langchain_community.document_loaders import WebBaseLoader
    loader = WebBaseLoader(
        web_paths=("https://blogs.nvidia.com/blog/what-is-retrieval-augmented-generation/",),
        bs_kwargs=dict(
            parse_only=bs4.SoupStrainer(
                class_=("entry-content", "entry-header", "entry-title")
            )
        ),
    )
    docs = loader.load()
    return docs


# TXT文本文件加载器加载生成文档
def load_docs_csv():
    from langchain_community.document_loaders.csv_loader import CSVLoader
    loader = CSVLoader(file_path='data/专业描述.csv', csv_args={
        'delimiter': ',',
        'quotechar': '"',
        'fieldnames': ['专业', '描述']
    }, encoding='utf8', source_column='专业')
    docs = loader.load()
    print(docs)
    return docs


# Word文件加载器加载生成文档
def load_docs_word():
    from langchain_community.document_loaders.word_document import UnstructuredWordDocumentLoader
    loader = UnstructuredWordDocumentLoader(file_path="data/demo.docx")
    # loader = UnstructuredWordDocumentLoader(file_path='data/demo.docx', mode="elements",strategy="fast", )
    docs = loader.load()
    print(docs)
    return docs

# PDF文件加载器加载生成文档
def load_docs_pdf():
    from langchain_community.document_loaders.pdf import UnstructuredPDFLoader
    loader = UnstructuredPDFLoader(file_path="../action/doc/Python编程：从入门到实践.pdf")
    # loader = UnstructuredPDFLoader(file_path='data/demo.pdf', mode="elements",strategy="fast", )
    docs = loader.load()
    print(docs)
    return docs

# PowerPoint文件加载器加载生成文档
def load_docs_ppt():
    from langchain_community.document_loaders.powerpoint import UnstructuredPowerPointLoader
    loader = UnstructuredPowerPointLoader(file_path="data/demo.ppt")
    # loader = UnstructuredPowerPointLoader(file_path='data/demo.pptx', mode="elements",strategy="fast", )
    docs = loader.load()
    print(docs)
    return docs

load_docs_pdf
